package com.allwees.bs.c.module.user.controller;

import com.allwees.bs.c.module.base.controller.BaseController;
import com.allwees.bs.c.module.user.req.CollectionReq;
import com.allwees.bs.c.module.user.service.ICollectionService;
import com.allwees.bs.core.modelbase.page.PageParams;
import com.allwees.bs.core.modelbase.vo.R;
import com.allwees.support.marketing.aop.ResetPrice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 收藏相关
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/user/collection")
@Validated
public class CollectionController extends BaseController {
	@Autowired
	private ICollectionService collectionService;

	/**
	 * 收藏商品
	 * @param req
	 * @return
	 */
	@PostMapping("/product/add")
	public R collProduct(@RequestBody CollectionReq req) {
		collectionService.collProduct(getUserUuid(), req.getUuid());
		return R.ok();
	}

	/**
	 * 取消商品收藏
	 * @param req
	 * @return
	 */
	@DeleteMapping("/product/cancel")
	public R cancelCollProduct(@Validated @RequestBody CollectionReq req) {
		collectionService.cancelCollProduct(getUserUuid(), req.getUuid());
		return R.ok();
	}

	/**
	 * 获取商品收藏列表
	 * @param pageParams
	 * @return
	 */
	@ResetPrice
	@GetMapping("/product")
	public R getCollProduct(PageParams pageParams) {
		return R.ok(collectionService.getCollProduct(getUserUuid(), pageParams));
	}

	/**
	 * 收藏店铺
	 * @param req
	 * @return
	 */
	@PostMapping("/store/add")
	public R collStore(@RequestBody CollectionReq req) {
		collectionService.collStore(getUserUuid(), req.getUuid());
		return R.ok();
	}

	/**
	 * 取消店铺收藏
	 * @param req
	 * @return
	 */
	@DeleteMapping("/store/cancel")
	public R cancelCollStore(@Validated @RequestBody CollectionReq req) {
		collectionService.cancelCollStore(getUserUuid(), req.getUuid());
		return R.ok();
	}

	/**
	 * 获取店铺收藏列表
	 * @param pageParams
	 * @return
	 */
	@GetMapping("/store")
	public R getCollStore(PageParams pageParams) {
		return R.ok(collectionService.getCollStore(getUserUuid(), pageParams));
	}
}
